package TeachLesson;

import TeachLesson.Res.ResDao;
import TeachLesson.Res.ResEnity;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.IOException;
import java.net.URLEncoder;

@WebServlet(name = "deleteResoursesServlet")
public class deleteResoursesServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request,response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
       /* String courseNo=request.getParameter("courseNo");
        String workerNo=request.getParameter("workerNo");
        String dirName=request.getParameter("dirName");
        String point=request.getParameter("point");

        String filePath="F:\\JWGLXT\\web\\StoreResoures\\"+workerNo+"\\"+courseNo+"\\"+dirName+"\\"+point;
        File file=new File(filePath,point);
        response.getWriter().println(filePath+point);
        file.delete();
        response.sendRedirect("/Teachers/knowledgeResourses.jsp?courseNo="+courseNo+"&workerNo="+workerNo+"&dirName="+ URLEncoder.encode(dirName,"UTF-8")+"&point="+URLEncoder.encode(point,"UTF-8"));
   */
        int id=Integer.parseInt(request.getParameter("id"));
        ResDao resDao=new ResDao();
        ResEnity resEnity=resDao.getRes(id);

        String fileRoot=resEnity.getFileRoot();
        String fileName=resEnity.getFileName();

        String filePathS=fileRoot+"/"+fileName;
        File file=new File(filePathS);
        response.getWriter().println(filePathS);
        if(file.exists()){
        file.delete();}
        //response.sendRedirect("/Teachers/knowledgeResourses.jsp");

        resDao.deleteRes(id);
        response.getWriter().println("删除成功");
    }
}
